using UnityEngine;
using System.Collections;

public class NextLevelButton : MonoBehaviour {
	
	public UILabel label;
	public UISprite icon;
	public UISprite loadingIcon;
	
	private float enabledTime = 0;
	
	private bool timeElapsed = false;
	
	void OnEnable(){
		label.text = "Chargement du niveau suivant";
		enabledTime = Time.time;
		icon.enabled = false;
		loadingIcon.enabled = true;
	}
	
	void Update(){
		if(enabledTime != 0 && Time.time - enabledTime > Camera.mainCamera.GetComponent<GameHandler>().endWaitTime){
			timeElapsed = true;
			label.text = "Passer au niveau suivant";
			icon.enabled = true;
			loadingIcon.enabled = false;
		}else{
			loadingIcon.gameObject.transform.Rotate(new Vector3(0,0,-300*Time.deltaTime));
		}
	}
	
	void OnClick(){
		if(timeElapsed){
			Camera.mainCamera.GetComponent<GameHandler>().loadNextLevel();
		}
	}	
}
